package com.aimosheng.video.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;


public class DoubleCliclView extends RelativeLayout {


    private GestureDetector mGesture;

    public DoubleCliclView(Context context) {
        super(context);
        init();
    }

    public DoubleCliclView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DoubleCliclView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        mGesture = new GestureDetector(getContext(),new GestureDetector.SimpleOnGestureListener(){
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                if(onDoubleClickListener!=null) {
                    onDoubleClickListener.onDoubleClick(DoubleCliclView.this);
                }
                return true;
            }

            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                if(onDoubleClickListener!=null) {
                    onDoubleClickListener.onSingleClick(DoubleCliclView.this);
                }
                return super.onSingleTapUp(e);
            }

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                return super.onFling(e1, e2, velocityX, velocityY);
            }

            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                return super.onScroll(e1, e2, distanceX, distanceY);
            }
        });
    }

    private OnDoubleClickListener onDoubleClickListener;
    //自定义监听器接口
    public interface OnDoubleClickListener{
        void onDoubleClick(View view);
        void onSingleClick(View view);
    }
    //设置双击事件监听器的方法
    public void setOnDoubleClickListener(OnDoubleClickListener onDoubleClickListener){
        this.onDoubleClickListener = onDoubleClickListener;
    };
//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        return mGesture.onTouchEvent(event);
//    }
}
